Many large businesses wish to take advantage of widespread use of the Internet to communicate with customers. However, communication protocols on the Internet are designed to deal primarily with text data, whereas numerical data is typically stored on computers in a non-text format. IEEE Standard 754 floating-point representation is the most commonly-used representation for real numbers on computers. IEEE Standard 754 floating-point representation represents real numbers in scientific notation, where each number has a mantissa, a base, and an exponent. For example, 62.25 could be represented as 62.25×100, where the mantissa is 62.25, the base is 10 and the exponent is 0 (indicating multiplication by 1). Preferably, floating-point numbers are stored in normalized form, which places the decimal point after the first non-zero digit. In normalized form, 62.25 is represented as 6.225×101. Computers store data in binary format, also referred to as base 2 numbers, which have digits that are either 1s or 0s. 62.25 in binary format is 111110.01×20 or 1.1111001×25 (normalized).
An important goal in the design of floating-point representation of numbers is to provide a representation that can approximate real numbers to a certain degree of accuracy. Consequently, a floating-point representation embodies the notions of significant digits and the location of the decimal point. IEEE Standard 754 floating-point numbers have three basic components: the sign, the exponent, and the mantissa. (The base of 2 is not explicitly represented.) The sign bit indicates whether the number is positive or negative. The mantissa is composed of a fraction, which corresponds to the significant digits, and may include an implicit leading digit. For example, in base 2, since the only possible non-zero digit is 1, a leading digit can be assumed and is not required to be stored explicitly, thereby saving storage space and increasing accuracy. The exponent indicates the location of the decimal point.
FIG. 1 shows the components of a floating-point representation of a real number and its binary equivalent. FIG. 1 includes various representations, including the IEEE 754 8-byte format, of the decimal number 3.14159. In exponential form, the number is represented as 3.14159*100. As a binary number, the number is represented as 11.0010010000111111001111100000001 (trailing zeros are omitted in this example). In binary exponential form, the number is shown as 1.10010010000111111001111100000001*21. In binary IEEE 754 8-byte form, the number has a one-bit sign component having a value of 0, indicating that the number is positive. The IEEE 754 8-byte form also includes an 11-bit exponent, in this example having a value of 100 0000 0000. Because the exponent field needs to represent both positive and negative exponents, a bias is added to the actual exponent to obtain the stored exponent. For IEEE 754 8-byte format, the bias is 1023. Thus, the value in the example of FIG. 1 is 1024 (indicating an exponent of 1=1024−1023).
The 52-bit mantissa, also known as a significand, represents the significant bits, also referred to as precision bits, of the number. In IEEE 754 8-byte format, the mantissa includes an implicit leading bit and the fraction bits. In FIG. 1, the mantissa has a value of 10010010000111111001111100000001 (the leading 1 of the binary exponential form is not shown because it is implicit, and trailing zeros are not shown). Before printing a number in IEEE 754 8-byte format, the stored value is usually converted from base 2 to a character string.
In IEEE 754 8-byte format, the largest and smallest binary numbers that can be represented are ±(2−2−52)1023. The largest and smallest decimal numbers that can be represented are approximately ±10308. Known conversion techniques may require up to 325 multiplication operations (308 for processing the exponent and one for each digit of a possible 17 digits in the mantissa) to convert the largest possible floating-point number to a character string. With web pages displaying numerous numerical values as character strings, conversion of real numbers to character strings can consume a substantial amount of CPU time and greatly reduce performance of web-based applications. In one example, CPU processing time spent by a web server to produce web pages and reports was analyzed. In that analysis, 67% of the CPU processing time of the web server was consumed by conversion of the floating-point representations of numbers into character strings. Similarly, another analysis of time spent by a Pentium IV processor using standardized conversion functions in a commonly available run-time library required from 6,000 to 14,000 cycles for each floating-point number converted to a character string.
What is needed is the ability to convert a floating-point representation of a number to a character string quickly, efficiently, and accurately. Preferably the technique would be useable by web servers in producing web pages and reports as well as by other software converting numerical data to character strings.